Vector¶

Vector is base class of other vector like classes. It represents a series of vectors.

In [1]:
from py3d import Vector
Vector()
Out[1]:
Vector([], dtype=float64)
In [3]:
Vector([0, 0, 0, 0])
Out[3]:
Vector([0, 0, 0, 0])
In [5]:
Vector([1, 2, -4])
Out[5]:
Vector([ 1,  2, -4])
In [7]:
Vector([1, 2, 3]).tile(2)
Out[7]:
Vector([[1, 2, 3],
        [1, 2, 3]])
In [9]:
import py3d
py3d.Vector([1, 2, 0, 3])
Out[9]:
Vector([1, 2, 0, 3])
In [10]:
Vector([1]).tile(2)
Out[10]:
Vector([[1],
        [1]])

Get unit vector

In [12]:
import py3d
V32 = py3d.Vector([
    [1, 3],
    [2, -9],
    [0.1, -3]])
V32.U
Out[12]:
Vector([[ 0.31622777,  0.9486833 ],
        [ 0.21693046, -0.97618706],
        [ 0.03331483, -0.99944491]])

Get length of vectors

In [13]:
V32.L
Out[13]:
array([3.16227766, 9.21954446, 3.0016662 ])
In [15]:
from numpy import allclose
assert allclose(V32.U.L, [[1], [1], [1]])

Get homogeneous vector

In [16]:
V32.H
Out[16]:
Vector3([[ 1. ,  3. ,  1. ],
         [ 2. , -9. ,  1. ],
         [ 0.1, -3. ,  1. ]])

Get a series of random vectors

In [18]:
import py3d
py3d.Vector.rand(2, 3, 4)
Out[18]:
Vector([[[0.09402348, 0.05120414, 0.41524834, 0.05066245],
         [0.08661841, 0.05856167, 0.53808521, 0.24977182],
         [0.10521296, 0.06030293, 0.23582831, 0.47021973]],

        [[0.49664182, 0.10423574, 0.22206041, 0.24066169],
         [0.08664804, 0.65222111, 0.62905366, 0.165561  ],
         [0.53557445, 0.89267619, 0.72357063, 0.79392496]]])
In [20]:
import py3d
py3d.Vector([[0, 0], [1, 2], [3, 4]]).diff()
Out[20]:
Vector([[1, 2],
        [2, 2]])

Write csv file

In [22]:
import py3d
py3d.Vector([[1,2,3],[4,5,6]]).to_csv("tmp.csv")

Read csv file

In [23]:
import py3d
py3d.read_csv("tmp.csv")
Out[23]:
Vector([[1., 2., 3.],
        [4., 5., 6.]])

Read pcd file

In [24]:
import py3d

py3d.read_pcd("ascii.pcd").xyz.as_point()
Out[24]:
In [25]:
import py3d
pcd = py3d.read_pcd("binary.pcd")
print("min", pcd.min())
print("max", pcd.max())
pcd.xyz.as_point().paint(py3d.Color.map(pcd.z))
min [-1.09082863e+02 -4.56674919e+01 -4.33038330e+00  2.50000000e+01  1.22393358e+09]
max [9.74602280e+01 8.35153122e+01 4.22846746e+00 2.55000000e+02 1.22393358e+09]
Out[25]:

Write npy file

In [26]:
import py3d
py3d.Vector([1,2,3]).to_npy("tmp.npy")

Read npy file

In [27]:
import py3d
py3d.read_npy("tmp.npy")
Out[27]:
Vector([1, 2, 3])

Read a real lidar point cloud from a npy file

In [28]:
import py3d
py3d.read_npy("lidar.npy").xyz.as_point()
Out[28]:

Read ply file

In [29]:
import py3d
vertices, mesh = py3d.read_ply("cube.ply")
print(vertices)
mesh
[[0. 0. 0.]
 [0. 0. 1.]
 [0. 1. 1.]
 [0. 1. 0.]
 [1. 0. 0.]
 [1. 0. 1.]
 [1. 1. 1.]
 [1. 1. 0.]]
Out[29]:
In [ ]: